package com.zzq.task;

import com.zzq.pojo.TenderInfo;
import com.zzq.tools.HotTenderCalculator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.zzq.mapper.TendererInfoMapper;

import java.time.LocalDateTime;
import java.util.List;

@Component
@Slf4j
public class HotTenderScheduledTask {

    @Autowired
    private TendererInfoMapper tenderInfoMapper;

    @Autowired
    private HotTenderCalculator hotTenderCalculator;

    // 每天凌晨2点计算热度
    @Scheduled(cron = "0 0 2 * * ?")
//    @Scheduled(fixedRate = 3000)
    public void updateHotTenders() {
        List<TenderInfo> allTenders = tenderInfoMapper.list();

        for (TenderInfo tender : allTenders) {
            double hotScore = hotTenderCalculator.calculateHotScore(tender);
            tender.setHotScore(hotScore);

            // 更新热度分数到数据库
            tenderInfoMapper.updateHotScore(tender.getTenderProjectNo(), hotScore);
        }

        log.info("热度计算完成，共更新 {} 个项目", allTenders.size());
    }
}

